﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Log;
using MiniFox.Resources;
using MiniFox.Utility;
using MiniFox.Web;
using MiniFox.Web.Configurations;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Web.Infrastructure
{
    /// <summary>
    /// 
    /// </summary>
    [AllowAnonymous, NoLog]
    public class ToolController : MvcControllerBase
    {
        /// <summary>
        /// 根据传入的内容绘制二维码图象
        /// </summary>
        /// <param name="content"></param>
        /// <param name="moduleSize"></param>
        /// <returns></returns>
        [HttpGet]
        public virtual IActionResult QrCode([FromQuery]string content, [FromQuery]int? moduleSize)
        {
            int size = moduleSize ?? 2;
            byte[] qrcode = content.ToQrCode(size);
            return File(qrcode, MimeTypes.Png);
        }
        /// <summary>
        /// 创建ID
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="suffix"></param>
        /// <param name="tailLen"></param>
        /// <param name="codeType"></param>
        /// <returns></returns>
        [HttpGet]
        public virtual Response<string> CreateID([FromQuery] string prefix, [FromQuery] string suffix, [FromQuery] byte tailLen, [FromQuery] CodeType codeType)
        {
            SequenceSetting sequenceSetting = new SequenceSetting(prefix, suffix, GlobalStandardFormat.SEQ_SIMPLE_DATETIME_FORMAT, tailLen, false, codeType);
            string id = new SequenceGUID(sequenceSetting);
            return id.CreateResponse();
        }
        /// <summary>
        /// 创建票据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public virtual Response<string> CreateTicket()
        {
            string ticket = new Ticket(SequenceGUID.NewGUID());
            return ticket.CreateResponse();
        }

    }
}
